package com.cloud.check.api.service.impl;

import com.cloud.check.api.bean.JgJgdxQyjbxxBean;
import com.cloud.check.api.entity.JgJgdxQyjbxx;
import com.cloud.check.api.mapper.JgJgdxQyjbxxMapper;
import com.cloud.check.api.service.JgJgdxQyjbxxService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

/**
 * Created by admin on 2019/9/20.
 */

@Service
@Transactional
public class JgJgdxQyjbxxServiceImpl implements JgJgdxQyjbxxService {

    @Autowired
    private JgJgdxQyjbxxMapper jgJgdxQyjbxxMapper;

    public PageInfo<JgJgdxQyjbxx> searchCorporation(JgJgdxQyjbxxBean jgJgdxQyjbxxBean){
        PageInfo<JgJgdxQyjbxx> page = null;
        Example example = new Example(JgJgdxQyjbxx.class);
        Example.Criteria criteria = example.createCriteria();
        if (StringUtils.isEmpty(jgJgdxQyjbxxBean.getUniSCID()) && StringUtils.isEmpty(jgJgdxQyjbxxBean.getEntName())) {
            page = PageHelper.startPage(jgJgdxQyjbxxBean.getPageNum(), jgJgdxQyjbxxBean.getPageSize())
                    .doSelectPageInfo(() -> {
                        jgJgdxQyjbxxMapper.findAllCorporation();
                    });
        } else {
            if (StringUtils.isNotEmpty(jgJgdxQyjbxxBean.getUniSCID())) {
                criteria.andLike("uniSCID", jgJgdxQyjbxxBean.getUniSCID() + "%");
            }
            if (StringUtils.isNotEmpty(jgJgdxQyjbxxBean.getEntName())) {
                criteria.andLike("entName", "%" + jgJgdxQyjbxxBean.getEntName() + "%");
            }
            page = PageHelper.startPage(jgJgdxQyjbxxBean.getPageNum(), jgJgdxQyjbxxBean.getPageSize())
                    .doSelectPageInfo(() -> {
                        jgJgdxQyjbxxMapper.selectByExample(example);
                    });
        }


        return page;
    }
}
